/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-11-04
 * Time: 10:02
 */
/*

class Solution {
    public int findPeakElement(int[] nums) {
        //暴力解法
        int n = nums.length , result = 0;
        if(n == 1){
            result = 0;
        }else if(nums[0] > nums[1]){
            result = 0;
        }else if(nums[n-1] > nums[n-2]){
            result = n-1;
        }else{
            int left = 0 , right = nums.length ;
            while(left < right){
                int mid = left + (right - left + 1)/2;
                if(nums[mid] > nums[mid-1]){
                    left = mid;
                }else if(nums[mid] < nums[mid-1]){
                    right = mid-1;
                }else{
                }
            }
            result = left;
        }
        return result;
    }
}
*/

class Solution6 {
    public int findPeakElement(int[] nums) {
        int left = 0 , right = nums.length-1;
        //如果数组中只有一个元素，while循环都进不去，规避了这个问题nb
        while(left < right){
            int mid = left + (right - left )/2;
            if(nums[mid+1] > nums[mid]){
                left = mid + 1;
            }else if(nums[mid+1] < nums[mid]){
                right = mid;
            }else{

            }
        }
        return left;
    }
}



public class Test6 {
    public static void main(String[] args) {
        Solution6 s = new Solution6();
        int[] array = {1};
        s.findPeakElement(array);
    }
}
